

$(document).ready(function (){

    queryFirms();

});

/**
 * 查询单个数据通过多个条件模糊查询
 */
function queryProvince(){

    $.ajax({
        url:"/manufacturer/queryProvince",
        type:"post",
        data:{},
        dataType:"json",
        success:function (result){
            var str = "<option selected='selected' value='0'>请选择</option>";
            for (var i = 0; i < result.length; i++) {
                str += "<option value='" + result[i].id + "'>"+result[i].pName+"</option>";
            }
            $("#prov").html(str);
        }
    })
}
let id;
function queryCity(){

    var id = $("#prov option:selected").val();
    $.ajax({
        url:"/manufacturer/queryCity",
        type:"post",
        data:{id:id},
        dataType:"json",
        success:function (result){
            var str = "<option selected='selected' value='0'>请选择</option>";
            for (var i = 0; i < result.length; i++) {
                str += "<option>"+result[i].c_Name+"</option>";
            }
            $("#cty").html(str);
        }
    })
}
function queryFirms(){
    id = window.sessionStorage.getItem('id');
    var proCity = window.sessionStorage.getItem('proCity');
    var status = window.sessionStorage.getItem('status');
    var creatTime = window.sessionStorage.getItem('creatTime');
    var creatPeople = window.sessionStorage.getItem('creatPeople');
    var ck = window.sessionStorage.getItem('ck');


    if (ck=="修改"){
        $.ajax({
            url:"/manufacturer/queryFirmDetails",
            type:"post",
            data:{id:id},
            dataType:"json",
            success:function (r){
                var str = "";
                for (let i = 0; i < r.data.length; i++) {
                    alert(r.data[i].firmName)
                    str +="<li><label>厂商名称</label><input type='text' className='dfinput' value='"+r.data[i].firmName+"' id='firmName' />" +
                        "<i>必填，不能超过50个字符</i></li><li><label>负责人</label>" +
                        "<input type='text' className='dfinput' id='founder' value='"+r.data[i].firmFounder+"'/><i>必填，不能超过30个字符</i>" +
                        "</li><li><label>联系方式</label><input name=\"\" type=\"text\" className=\"dfinput\" id=\"tel\" value='"+r.data[i].firmTel+"'/>" +
                        "<i>必填，不能超过30个字符</i></li><li><label>联系地址</label><input type=\"text\" className=\"dfinput\" id=\"address\" value='"+r.data[i].firmAddress+"'/>" +
                        "<i>必填，不能超过130个字符</i></li><li><label>所属区域</label><select className=\"dfselect\" id=\"prov\" onChange=\"queryCity()\"></select>" +
                        "省<select className=\"dfselect\" id=\"cty\"></select>市<i>必选</i></li><li><label>描述</label><textarea className=\"textinput\" id=\"wenben\">"+r.data[i].firmContent+"</textarea>" +
                        "<i>可选</i></li><li><label>状态</label><select className=\"dfselect\" id=\"status\"><option value=\"1\">可用</option><option value=\"0\">不可用</option></select>" +
                        "<i>必选</i></li><li><label>创建人</label><input type=\"text\" readOnly='readonly' className=\"roinput\" id=\"creatName\" value='"+creatPeople+"'/>" +
                        "<i>不能编辑</i></li><li><label>创建时间</label><input name=\"\" type=\"text\" readOnly='readonly' className=\"roinput\" id=\"creatTime\" value='"+creatTime+"'/>" +
                        "<i>不能编辑</i></li><li><label>&nbsp;</label><input name=\"\" type=\"button\" className=\"btn\" value=\"确定\" onClick='updateFirm()'/>" +
                        "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name=\"\" type=\"button\" className=\"btn\" value=\"返回\" onClick=\"window.location.href='manufacturerList.html'\"/></li>";
                }
                $(".forminfo").html(str);
                queryProvince();
            }
        })
    }
}



function updateFirm(){

    var Fname = $("#firmName").val();
    var founder = $("#founder").val();
    var tel = $("#tel").val();
    var address = $("#address").val();
    var city = $("#cty option:selected").text();
    var content = $("#wenben").val();
    var status = $("#status option:selected").val();
    $.ajax({
        url:"/manufacturer/updateFirm",
        type:"post",
        data:{id:id,Fname:Fname,founder:founder,tel:tel,address:address,city:city,content:content,status:status},
        dataType:"json",
        success:function (result){
            if (result=="true"){
                alert("修改成功");
            }else {
                alert("修改失败");
            }
        }
    })
}